package com.coolrui.domain.prometheus;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 订单服务-自定义业务监控
 */
@Component
@Slf4j
public class OrderMetricsService {
    private static final String serviceName = "UserOrderService";
    @Autowired
    private RequestMetricsService requestMetricsService;
    @Autowired
    private AmountMetricsService amountMetricsService;

    // 监控埋点-请求QPS指标
    public void recordRequest(String methodName) {
        String uri = serviceName+"."+methodName;
        // 记录请求次数
        requestMetricsService.recordRequest(uri, serviceName);
    }

    /**
     * 监控埋点-订单总金额指标
     * @param amount 订单金额（单位：元）
     */
    public void recordAmount(BigDecimal amount) {
        amountMetricsService.addOrderAmount(amount);
    }

    /**
     * 监控埋点-订单总金额指标
     * @param amount 订单金额（单位：元）
     * @param type 订单类型
     */
    public void recordAmount(BigDecimal amount, String type) {
        amountMetricsService.addOrderAmount(amount, type);
    }
}


